<template>
  <div class="monitor_page">
    <div class="monitor_page-filter">
      <el-form ref="form" label-width="100px" :inline="true">
        <el-form-item label="起止时间：">
          <el-date-picker
            style="width:100%;min-width:350px"
            size="small"
            value-format="timestamp"
            v-model="timerArray"
            type="datetimerange"
            :picker-options="pickerOptions"
            :clearable="false"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="解算类型：" v-if="EnumSurfaceCalcTypeList.length!==0">
          <el-select v-model.trim="EnumSurfaceCalcTypeModel" clearable placeholder="解算类型"
                     style="width: 120px;margin: 0 20px;margin-left: 2px" size="small">
            <el-option v-for="item in EnumSurfaceCalcTypeList" :key="item.code" :label="item.name"
                       :value="item.code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="筛选条件：" style="margin-right: 20px">
          <el-select
            v-model.trim="compareTypeModel"
            size="small">
            <el-option
              v-for="item in compareTypes"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label-width="60px" label="数值：" style="margin-right: 20px">
          <el-input type="number" v-model="compareValModel" placeholder="可输入" size="small" style="width: 60%">
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="monitor_page-filter flex-between">
      <div class="monitor_page-filter-left">
        <el-button
          @click="confirmDelete"
          icon="el-icon-delete-solid"
          v-if="hasPermission('monitor:record:del')"
          type="danger">删除
        </el-button>
        <el-button
          plain
          v-if="hasPermission('monitor:record:mark')"
          type="primary"
          @click="showMonitorRemarkDialog">说明
        </el-button>
        <el-button
          plain
          v-if="hasPermission('monitor:record:export')"
          @click="$emit('export')"
          icon="el-icon-download"
          type="primary">数据导出
        </el-button>
        <el-button
          plain
          v-if="hasPermission('monitor:record:clean')"
          icon="el-icon-s-tools"
          type="primary"
          @click="showMonitorResetWaringDialog('compensateInAngle',)">预警值重置
        </el-button>
        <el-button
          type="primary"
          class="common_btn-defalut"
          icon="el-icon-search"
          @click="form.page=1;$emit('update')">搜索
        </el-button>
      </div>
    </div>
    <div style="width: 100%;padding-left: 10px">
      <el-tabs type="border-card" v-model="activeName2" @tab-click="clickTab">
        <el-tab-pane label="数据表格" name="1">
          <span slot="label"><i class="el-icon-date"></i> 数据表格</span>
          <el-table
            v-show="!isToggleStatus"
            :data="tableList"
            border
            @selection-change="handleSelectionChange"
            ref="multipleTable"
            tooltip-effect="dark">
            <el-table-column type="selection" width="28">
            </el-table-column>
            <el-table-column prop="createTime" label="数据采集时间" header-align="center" min-width="140">
              <template slot-scope="scope">
                {{scope.row.createTime | formatTimer }}
              </template>
            </el-table-column>
            <el-table-column label="变化值(mm)" header-align="center">
              <el-table-column
                header-align="center"
                prop="yDisplacement"
                label="东向标"
                min-width="80">
              </el-table-column>
              <el-table-column
                header-align="center"
                prop="xDisplacement"
                label="北向标"
                min-width="80">
              </el-table-column>
              <el-table-column
                header-align="center"
                prop="zDisplacement"
                label="天向标"
                min-width="80">
              </el-table-column>
              <el-table-column
                header-align="center"
                prop="xyDisplacement"
                label="平面合成"
                min-width="80">
              </el-table-column>
            </el-table-column>
            <!--              <el-table-column label="变化速率(mm/h)" header-align="center">-->
            <!--                <el-table-column-->
            <!--                  header-align="center"-->
            <!--                  prop="xSpeed"-->
            <!--                  label="X"-->
            <!--                  min-width="80">-->
            <!--                </el-table-column>-->
            <!--                <el-table-column-->
            <!--                  header-align="center"-->
            <!--                  prop="ySpeed"-->
            <!--                  label="Y"-->
            <!--                  min-width="80">-->
            <!--                </el-table-column>-->
            <!--                <el-table-column-->
            <!--                  header-align="center"-->
            <!--                  prop="zSpeed"-->
            <!--                  label="Z"-->
            <!--                  min-width="80">-->
            <!--                </el-table-column>-->
            <!--                <el-table-column-->
            <!--                  header-align="center"-->
            <!--                  prop="xySpeed"-->
            <!--                  label="XY"-->
            <!--                  min-width="80">-->
            <!--                </el-table-column>-->
            <!--                <el-table-column-->
            <!--                  header-align="center"-->
            <!--                  prop="xyzSpeed"-->
            <!--                  label="XYZ"-->
            <!--                  min-width="80">-->
            <!--                </el-table-column>-->
            <!--              </el-table-column>-->
            <!--              <el-table-column label="原始值" header-align="center">-->
            <!--                <el-table-column-->
            <!--                  header-align="center"-->
            <!--                  prop="xCoordinate"-->
            <!--                  label="X"-->
            <!--                  min-width="80">-->
            <!--                </el-table-column>-->
            <!--                <el-table-column-->
            <!--                  header-align="center"-->
            <!--                  prop="yCoordinate"-->
            <!--                  label="Y"-->
            <!--                  min-width="80">-->
            <!--                </el-table-column>-->
            <!--                <el-table-column-->
            <!--                  header-align="center"-->
            <!--                  prop="zCoordinate"-->
            <!--                  label="Z"-->
            <!--                  min-width="80">-->
            <!--                </el-table-column>-->
            <!--              </el-table-column>-->

          </el-table>
          <!-- 分页器 -->
          <el-pagination
            v-show="!isToggleStatus"
            :disabled="isToggleStatus"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="form.page"
            :page-sizes="[10, 20, 30, 40,50,60,70,80,90,100]"
            :page-size="form.pageSize"
            layout="sizes, prev, pager, next,jumper"
            :total="form.total">
          </el-pagination>

        </el-tab-pane>
        <el-tab-pane label="数据绘图" name="2">
          <span slot="label"><i class="el-icon-s-marketing"></i> 数据绘图</span>
          <el-tabs v-model="activeName" @tab-click="clickTab">
            <el-tab-pane label="数据图" name="1">
              <el-switch
                @change="changeSwitch()"
                v-model="isShowWarningLine"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-text="预警等级线开启"
                inactive-text="预警等级线关闭">
              </el-switch>
              <el-card class="card_echarts" shadow="hover">
                <echarts-displacement ref="echartsDisplacement"></echarts-displacement>
              </el-card>
            </el-tab-pane>
            <el-tab-pane label="速率图" name="2">
              <el-card class="card_echarts" shadow="hover">
                <echarts-speed ref="echartsSpeed"></echarts-speed>
              </el-card>
            </el-tab-pane>
            <el-tab-pane label="方位角散点图" name="3">
              <el-card class="card_echarts" shadow="hover">
                <echarts-angle ref="echartsAngle"></echarts-angle>
              </el-card>
            </el-tab-pane>
            <!--        <el-tab-pane label="东西沉降轨迹图" name="东西沉降轨迹图">-->
            <!--          <el-card class="card_echarts" shadow="hover">-->
            <!--            <echarts-two-change ref="echartsTwoChange2"></echarts-two-change>-->
            <!--          </el-card>-->
            <!--        </el-tab-pane>-->
            <!--        <el-tab-pane label="南北沉降轨迹图" name="南北沉降轨迹图">-->
            <!--          <el-card class="card_echarts" shadow="hover">-->
            <!--            <echarts-two-change ref="echartsTwoChange3"></echarts-two-change>-->
            <!--          </el-card>-->
            <!--        </el-tab-pane>-->
          </el-tabs>
        </el-tab-pane>
      </el-tabs>
    </div>

    <monitor-remark ref="monitorRemark" @update="$emit('update')"></monitor-remark>
    <monitor-reset ref="monitorReset" @update="$emit('update')"></monitor-reset>
  </div>
</template>

<script>
  import ItemMixins from './item.mixins'
  import EchartsDisplacement from '../monitor-echarts/base/echarts-2-displacement'
  import EchartsSpeed from '../monitor-echarts/base/echarts-2-speed'
  import EchartsAngle from '../monitor-echarts/base/echarts-2-angle'
  import {store} from "../../work-point.store";

  export default {
    props: ['surfaceCalcType', 'enumSurfaceCalcTypeList', 'compareType', 'compareTypes', 'compareVal'],
    mixins: [ItemMixins],
    components: {EchartsDisplacement, EchartsSpeed, EchartsAngle},

    data() {
      return {
        activeName2: "2",
        isShowWarningLine: true,
        activeName: '1',
        // 当前的图表钩子
        chartsName: ['echartsDisplacement', 'echartsSpeed', 'echartsAngle'],
        // 分页参数
        form: {
          page: 1,
          pageSize: 12,
          total: 0,
        },
        isShowDialog: false
      }
    },

    computed: {
      compareTypeModel: {
        get() {
          return this.compareType;
        },
        set(value) {
          this.$emit("update:compareType", value);
        },
      },
      compareValModel: {
        get() {
          return this.compareVal;
        },
        set(value) {
          this.$emit("update:compareVal", value);
        },
      },
      EnumSurfaceCalcTypeList: {
        get() {

          return this.enumSurfaceCalcTypeList;

        },
      },
      EnumSurfaceCalcTypeModel: {
        get() {
          return this.surfaceCalcType;
        },
        set(value) {
          if (this.EnumSurfaceCalcTypeList.length == 0) {
            this.$emit("update:surfaceCalcType", null);
          } else {
            this.$emit("update:surfaceCalcType", value);
          }

        },
      },
      //工点类型是否是建筑物，建筑物不展示边坡相关的信息
      workPointTypeIsBuilding() {
        const {
          workPointId
        } = this.$route.params
        const info = store.workPointList.find(x => x.id === workPointId) || {}
        return info.bianpiType === 6
      }
    },
    methods: {
      //tab 切换进行echart随着窗口改变方法，让数据重新渲染，
      clickTab() {
        this.chartsName.map((name) => {
          if (this.$refs[name]) {
            this.$nextTick(() => {
              this.$refs[name].echartResize();
            });
          }
        });

      },
      changeSwitch() {
        this.$refs.echartsDisplacement.changeShowWarningLine(this.isShowWarningLine)
      },
      // 数据刷新
      update({data, monitorName, monitorInfo}) {
        this.isShowWarningLine = true
        this.equipId = monitorInfo.bindEquipId

        this.collectionList = data.recordList || []
        this.form.page = 1;
        this.form.total = this.collectionList.length
        this.$refs.echartsDisplacement.updateEchart(data, monitorName)
        this.$refs.echartsDisplacement.changeShowWarningLine(this.isShowWarningLine)
        this.$refs.echartsSpeed.updateEchart(data, monitorName)
        this.$refs.echartsAngle.updateEchart(data.xDisplacement, data.yDisplacement, monitorName)
        // this.$refs.echartsTwoChange1.updateEchart(data.xDisplacement, data.yDisplacement, "水平轨迹图（单位：mm）", "东向", "北向","西向","南向")
        // this.$refs.echartsTwoChange2.updateEchart(data.yDisplacement, data.zDisplacement, "东西沉降轨迹图（单位：mm）", "东向", "天向","西向","地向")
        // this.$refs.echartsTwoChange3.updateEchart(data.xDisplacement, data.zDisplacement, "南北沉降轨迹图（单位：mm）", "北向", "天向","南向","地向")
      },
    },
    mounted() {

    }
  }
</script>

<style scoped="scoped" lang="less">

  @import url('./commom.less');

  .el-tabs {
    width: 100%;
  }

  // 还需自定义的css
  .card_echarts {
    height: 500px;
  }


  .monitor_page {
    /deep/ .el-tabs__item {
      font-size: 15px;
    }

    /deep/ .el-tabs__item.is-active {
      font-size: 18px;
    }

    /deep/ .el-tabs--border-card > .el-tabs__header .el-tabs__item:not(.is-disabled):hover {
      font-size: 18px;
    }
  }

  .filter_select {
    .el-select {
      width: 40%;
    }
  }

  .el-card {
    background: transparent;
  }

  /deep/ .el-tabs__item {
    color: #1990FE !important;
  }
</style>
